package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 将article表中的数据查询出来并输出到控制台上
 */
public class Test4 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            String sql = "SELECT title,content FROM article";
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                String title = rs.getString("title");
                String content = rs.getString("content");
                System.out.println(title+","+content);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
